/*
 * Copyright (C) 2010, Funcom AS, All Rights Reserved
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *  @authors
 *  Svein Gunnar Larsen <sveingunnarlarsen@gmail.com>
 *  Erik Thune Lund <culex.eriklund@gmail.com>
 *  Michel Krohn-Dale <kronicz@gmail.com>
 */

package com.funcom.peeler.properties;

import com.funcom.peeler.WorkBench;
import com.funcom.peeler.peelable.PeelComponent;

import java.util.Set;

// Abstract class for classes that manage component or stylesheet changes.
public abstract class UpdateableProperties {

    // Changes that can be applied to components.
    public enum ChangeProp {
        NONE, SIZE, POSITION, NEW_STYLE, NAME, BACKGROUND_IMAGE, BACKGROUND_COLOR, CLEAR_RULE, EFFECT_COLOR, DELETE_RULE,
        BACKGROUND_CLEAR, PADDING, TEXT, TEXT_COLOR, TEXT_EFFECT, EFFECT_SIZE, ALIGNMENT, FONT, CHANGE_STYLE, ALPHA, HIDE_LOCK
    }

    // The first/main selected components in the selection layer.
    protected PeelComponent selectedComp = null;
    // Change to be applied in the next update of applyChange if change is NONE no update is needed.
    protected ChangeProp change = ChangeProp.NONE;

    // boolean that is set to true if the class itself need an update of its layout.
    protected boolean wantUpdate = false;
    protected boolean fields_cleared = false;

    public boolean wantUpdate() {
        return wantUpdate;
    }

    public void updateDone() {
        fields_cleared = false;
        wantUpdate = false;
    }

    public boolean hasNewChange() {
        return change != ChangeProp.NONE;
    }

    public void changeApplied() {
        change = ChangeProp.NONE;
    }

    // Updates layout.
    public abstract void update();

    // *Check if the class needs an update of layout.
    public abstract void needUpdate( WorkBench wantUpdate,
                                     Set<PeelComponent> allComp,
                                     Set<PeelComponent> selectedComps,
                                     PeelComponent main_selected,
                                     PropertiesFrame frame);

    // Apply the change to the selected component if change != NONE.
    public abstract void applyChange( PeelComponent component, PropertiesFrame updater );

    // Clear layout.
    public abstract void clear();

    protected abstract void initListeners();

}
